package com.fourhats.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fourhats.services.ItemService;
import com.fourhats.services.PlaceService;
import com.fourhats.services.PriceService;
import com.fourhats.services.dto.PlaceDto;
import com.fourhats.services.dto.ItemDto;

@Controller
public class PlaceController {

	@Autowired
	private PlaceService placeService;
	
	@Autowired
	private ItemService itemService;
	 
	@Autowired
	private PriceService priceService;
	
	@RequestMapping(value="/index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("index");
        return modelAndView;
    }
	
//	@RequestMapping(value="/place/getNearbyPlaces")
//	public @ResponseBody List<PriceDto> getPlaces(@RequestParam String sLat, @RequestParam String sLng,@RequestParam String sDist){
//		List<Long> placesIds = this.placeService.getNearbyPlaces(Double.parseDouble(sLat), Double.parseDouble(sLng), Float.parseFloat(sDist));
//		if(placesIds.size() == 0){
//			return new ArrayList<PriceDto>();
//		}
//		
//		return this.priceService.getEnabledPricesByItemAndPlace(1, placesIds);
//	}
	
	@RequestMapping(value="/place/getNearbyPlaces")
	public @ResponseBody List<PlaceDto> getPlaces(@RequestParam String sLat, @RequestParam String sLng,@RequestParam String sDist){
		return this.placeService.getNearbyPlaces(Double.parseDouble(sLat), Double.parseDouble(sLng), Float.parseFloat(sDist));
	}
	
	@RequestMapping(value="/products")
    public ModelAndView products() {
		List<ItemDto> products = this.itemService.getItemsByKeyword("l");
        ModelAndView modelAndView = new ModelAndView("product", "products", products);
        return modelAndView;
    }
}
